
Partial Class FanClub
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then
            DisplayProfileProperties()
        End If
    End Sub

    Sub btnCancelChanges_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        DisplayProfileProperties()

    End Sub

    Sub btnSaveChanges_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        Profile.Theme = CType(FCLoginView.FindControl("ThemeList"), DropDownList).SelectedValue
        Profile.Name = CType(FCLoginView.FindControl("txtName"), TextBox).Text
        Profile.Address = CType(FCLoginView.FindControl("txtAddress"), TextBox).Text
        Profile.City = CType(FCLoginView.FindControl("txtCity"), TextBox).Text
        Profile.County = CType(FCLoginView.FindControl("txtCounty"), TextBox).Text
        Profile.PostCode = CType(FCLoginView.FindControl("txtPostCode"), TextBox).Text
        Profile.Country = CType(FCLoginView.FindControl("txtCountry"), TextBox).Text
        Profile.Mailings = CType(FCLoginView.FindControl("chkMailing"), CheckBox).Checked
        Profile.Email = CType(FCLoginView.FindControl("txtEmail"), TextBox).Text
        Profile.MemberName = CType(FCLoginView.FindControl("txtAlias"), TextBox).Text
        Server.Transfer(SiteMap.CurrentNode.Url)

    End Sub

    Sub FCLoginView_ViewChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        DisplayProfileProperties()

    End Sub

    Private Sub DisplayProfileProperties()

        Dim ThemeList As DropDownList = CType(FCLoginView.FindControl("ThemeList"), DropDownList)

        ' TODO
        ' there should be a better way of detecting whether a certain template is in action
        ' as it is we have to just see if the control exists, and if so we can set its value
        If Not (ThemeList Is Nothing) Then
            ThemeList.SelectedValue = Profile.Theme
            CType(FCLoginView.FindControl("txtName"), TextBox).Text = Profile.Name
            CType(FCLoginView.FindControl("txtAddress"), TextBox).Text = Profile.Address
            CType(FCLoginView.FindControl("txtCity"), TextBox).Text = Profile.City
            CType(FCLoginView.FindControl("txtCounty"), TextBox).Text = Profile.County
            CType(FCLoginView.FindControl("txtPostCode"), TextBox).Text = Profile.PostCode
            CType(FCLoginView.FindControl("txtCountry"), TextBox).Text = Profile.Country
            CType(FCLoginView.FindControl("chkMailing"), CheckBox).Checked = Profile.Mailings
            CType(FCLoginView.FindControl("txtEmail"), TextBox).Text = Profile.Email
            CType(FCLoginView.FindControl("txtAlias"), TextBox).Text = Profile.MemberName
        End If

    End Sub

End Class
